
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using Csla.Validation;

namespace SariturIntranetLibrary.Agendas
{
    [Serializable()]
    public class AgendaChildInfo : Csla.ReadOnlyBase<AgendaChildInfo>
    {

        #region Business Properties and Methods

        //declare members

        private Guid _id = Guid.NewGuid();

        private SmartDate _data = new SmartDate(false);

        private string _titulo = string.Empty;

        private string _descricao = string.Empty;

        [System.ComponentModel.DataObjectField(true, false)]
        public Guid Id
        {
            get
            {
                CanReadProperty("Id", true);
                return _id;
            }
        }

        public DateTime Data
        {
            get
            {
                CanReadProperty("Data", true);
                return _data.Date;
            }
        }

        public string DataString
        {
            get
            {
                CanReadProperty("DataString", true);
                return _data.Text;
            }
        }

        public string Titulo
        {
            get
            {
                CanReadProperty("Titulo", true);
                return _titulo;
            }
        }

        public string Descricao
        {
            get
            {
                CanReadProperty("Descricao", true);
                return _descricao;
            }
        }

        protected override object GetIdValue()
        {
            return _id;
        }

        #endregion //Business Properties and Methods

        #region Authorization Rules
        protected override void AddAuthorizationRules()
        {
            //TODO: Define authorization rules in AgendaChildInfo
            //AuthorizationRules.AllowRead("Id", "AgendaChildInfoReadGroup");
            //AuthorizationRules.AllowRead("Data", "AgendaChildInfoReadGroup");
            //AuthorizationRules.AllowRead("DataString", "AgendaChildInfoReadGroup");
            //AuthorizationRules.AllowRead("Titulo", "AgendaChildInfoReadGroup");
            //AuthorizationRules.AllowRead("Descricao", "AgendaChildInfoReadGroup");

        }

        #endregion //Authorization Rules

        #region Factory Methods
        internal static AgendaChildInfo GetAgendaChildInfo(SafeDataReader dr)
        {
            return new AgendaChildInfo(dr);
        }

        private AgendaChildInfo(SafeDataReader dr)
        {
            Fetch(dr);
        }
        #endregion //Factory Methods


        #region Data Access

        #region Data Access - Fetch
        private void Fetch(SafeDataReader dr)
        {
            FetchObject(dr);

            //load child object(s)
            FetchChildren(dr);

        }

        private void FetchObject(SafeDataReader dr)
        {
            _id = dr.GetGuid("Id");
            _data = dr.GetSmartDate("Data", _data.EmptyIsMin);
            _titulo = dr.GetString("Titulo");
            _descricao = dr.GetString("Descricao");
        }

        private void FetchChildren(SafeDataReader dr)
        {
        }
        #endregion //Data Access - Fetch
        #endregion //Data Access
    }
}
